# delimit ;

clear;
*version 13;
set matsize 400;
set more off;


log using "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Unconditional/Severity/PredictedValues.log", replace;
cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Unconditional/Severity";

**************************************************************;
*Author: Jeff Carter                                         *;
*Date: Saturday, May 23, 2015                              *;
*Purpose: Simulating Predictions                *;
**************************************************************;

** Need Legend for Probabilities and Differences  **;

use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Unconditional/Severity/SimData.dta";

postutil clear;

postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 hi5
                diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2 
                using PredictedValues, replace;

noisily display "start";


local a=0 ;
while `a' < .1 { ;

{;



scalar h_Accountable =   0  ;
scalar h_LameDuck= 1  ;
scalar h_Civilian = 0;
scalar h_Military = 1;
scalar h_Constant = 1;
scalar h_Parliament = 0;
scalar h_CivilWar = 0;
scalar h_GDPpc =  12589.35;
scalar h_Growth = 3.453132;
scalar h_MajorPower = 0;
scalar h_Borders = 2;
scalar h_Mobilization =  -.0008714 ;
scalar h_Time = 5; 
scalar h_Rivalry = 0;
scalar h_Female = 0;
scalar h_Hawkish = 0;


generate x_betahat0 = MG_b1*h_Accountable
    + MG_b2*h_Hawkish
    + MG_b3*h_Rivalry
    + MG_b4*h_Borders
    + MG_b5*h_Parliament
    + MG_b6*h_Female 
    + MG_b7*h_Time
    + MG_b8*(h_Time^2)
    + MG_b9*(h_Time^3);

generate x_betahat1 = MG_b1* h_LameDuck
    + MG_b2*h_Hawkish
    + MG_b3*h_Rivalry
    + MG_b4*h_Borders
    + MG_b5*h_Parliament
    + MG_b6*h_Female 
    + MG_b7*h_Time
    + MG_b8*(h_Time^2)
    + MG_b9*(h_Time^3);


gen prob0=  1/(1+exp(x_betahat0-MG_b10));
gen prob1=   (1/(1+exp(x_betahat0-MG_b11)))  -  (1/(1+exp(x_betahat0-MG_b10)))  ;
gen prob2=   1- (1/(1+exp(x_betahat0-MG_b11)));

gen prob3=  1/(1+exp(x_betahat1-MG_b10));
gen prob4=  (1/(1+exp(x_betahat1-MG_b11)))  -  (1/(1+exp(x_betahat1-MG_b10)))  ;
gen prob5=   1- (1/(1+exp(x_betahat1-MG_b11)));

        
gen diff0=prob3-prob0 ;
gen diff1=prob4-prob1 ;
gen diff2=prob5-prob2 ;



        
egen probhat0=mean(prob0) ;
egen probhat1=mean(prob1) ;
egen probhat2=mean(prob2) ;
egen probhat3=mean(prob3) ;
egen probhat4=mean(prob4) ;
egen probhat5=mean(prob5) ;


egen diffhat0=mean(diff0) ;
egen diffhat1=mean(diff1) ;
egen diffhat2=mean(diff2) ;






tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 hi5
        diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2;




        
    _pctile prob0, p(2.5,97.5) ;
    scalar `lo0'=r(r1) ;
    scalar `hi0'=r(r2) ;

    _pctile prob1, p(2.5,97.5) ;
    scalar `lo1'=r(r1) ;
    scalar `hi1'=r(r2) ;

    _pctile prob2, p(2.5,97.5) ;
    scalar `lo2'=r(r1) ;
    scalar `hi2'=r(r2) ;

    _pctile prob3, p(2.5,97.5) ;
    scalar `lo3'=r(r1) ;
    scalar `hi3'=r(r2) ;

    _pctile prob4, p(2.5,97.5) ;
    scalar `lo4'=r(r1) ;
    scalar `hi4'=r(r2) ;

    _pctile prob5, p(2.5,97.5) ;
    scalar `lo5'=r(r1) ;
    scalar `hi5'=r(r2) ;

        
    _pctile diff0, p(2.5,97.5) ;
    scalar `diff_lo0'= r(r1) ;
    scalar `diff_hi0'=r(r2) ;

    _pctile diff1, p(2.5,97.5) ;
    scalar `diff_lo1'= r(r1) ;
    scalar `diff_hi1'=r(r2) ;

    _pctile diff2, p(2.5,97.5) ;
    scalar `diff_lo2'= r(r1) ;
    scalar `diff_hi2'=r(r2) ;
        
    scalar `prob_hat0'=probhat0 ;
    scalar `prob_hat1'=probhat1 ;
    scalar `prob_hat2'=probhat2 ;
    scalar `prob_hat3'=probhat3 ;
    scalar `prob_hat4'=probhat4 ;
    scalar `prob_hat5'=probhat5 ;

      
    scalar `diff_hat0'=diffhat0 ;
    scalar `diff_hat1'=diffhat1 ;
    scalar `diff_hat2'=diffhat2 ;



 post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
        (`prob_hat3') (`lo3') (`hi3') (`prob_hat4') (`lo4') (`hi4') (`prob_hat5') (`lo5') (`hi5')
        (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1') (`diff_hat2') (`diff_lo2') (`diff_hi2')


    ;

    } ;

drop    x_betahat0 x_betahat1
        prob0 prob1 prob2 prob3 prob4 prob5
        diff0 diff1 diff2
        probhat0 probhat1 probhat2 probhat3 probhat4 probhat5
        diffhat0 diffhat1 diffhat2;

    local a=`a'+ .1 ;

    display "." _c ;
    } ;
display "" ; postclose mypost ;



use PredictedValues, clear;
sum;

saveold PredictedValues, replace;


log close;
